﻿using System;
using System.Drawing;
using System.IO;

namespace OutlookContactsSync.Services
{
    public static class ImageHelper
    {
        public static Image ByteArrayToImage(byte[] byteArrayIn)
        {
            try
            {
                Image returnImage = null;

                using (var ms = new MemoryStream(byteArrayIn))
                {
                    returnImage = Image.FromStream(ms);
                }

                return returnImage;
            }
            catch (Exception ex) 
            {
                //Sometimes an exception will be thrown considering an invalid parameter.
                //Do not seem to be able to fix this or do anyting about it, just return null.

                return null;
            }
        }
    }
}